<&javascript delayed='true'>
// Gets an optimum time value in either min/sec/days/years etc
function getTimeValue (time)
{
if (time >= 31536000000)
{
// Time is greater than or equal to 1 year
this.type = "Years";
this.time = time / 31536000000;
}
else if (time >= 2419200000)
{
// Time is greater than or equal to 28 days (~1 month)
this.type = "Months";
this.time = time / 2419200000;
}
else if (time >= 604800000000)
{
// Time is greater than or equal to 1 week
this.type = "Weeks";
this.time = time / 604800000;
}
else if (time >= 86400000)
{
// Time is greater than or equal to 1 day
this.type = "Days";
this.time = time / 86400000;
}
else if (time >= 3600000)
{
// Time is greater than or equal to 1 hour
this.type = "Hours";
this.time = time / 3600000;
}
else if (time >= 60000)
{
// Time is greater than or equal to 1 minute
this.type = "Minutes";
this.time = time / 60000;
}
else
{
this.type = "Seconds";
this.time = time / 1000;
}
return this;
}
function createTimeOptions(name, defaultType)
{
var result = "";
var options = ['Seconds', 'Minutes', 'Hours', 'Days' , 'Weeks' , 'Months' , 'Years' ];
var values = [1000 , 60000 , 3600000, 86400000, 604800000, 2419200000, 31536000000];
result += "";
return result;
}
for ( i in parameters.ReturnData )
{
var consolidationPeriod = parameters.ReturnData[i];
var timeBefore = new getTimeValue(consolidationPeriod.Period);
var resolution = new getTimeValue(consolidationPeriod.Resolution);
output = "";
output += "";
output += " | ";
output += createTimeOptions("timeBeforeType", timeBefore.type) + " ago | ";
output += " ";
output += createTimeOptions("resolutionType", resolution.type) + " per measurement. | ";
output += " | ";
output += "
";
$("#consolTableBody").append(output);
// Add remove button event handler
$("tr[consolid='" + consolidationPeriod.Id + "'] button.removeButton").bind('click', {id: consolidationPeriod.Id}, function(e)
{
if ($(this).html() == "Remove")
{
$(this).html("Undo");
$("tr[consolid='" + e.data.id + "']").toggleClass("disabled", true);
$("tr[consolid='" + e.data.id + "'] input").attr("disabled", true);
$("tr[consolid='" + e.data.id + "'] select").attr("disabled", true);
}
else
{
$(this).html("Remove");
$("tr[consolid='" + e.data.id + "']").toggleClass("disabled", false);
$("tr[consolid='" + e.data.id + "'] input").attr("disabled", false);
$("tr[consolid='" + e.data.id + "'] select").attr("disabled", false);
}
});
}
window.log_consolidation_table_count = parameters.ReturnData.length;
$("#consolTableBody").append(" | | |
");
$(".addButton").click(function()
{
output = "";
output += "";
output += " | ";
output += createTimeOptions("timeBeforeType", "Seconds") + " ago | ";
output += " ";
output += createTimeOptions("resolutionType", "Seconds") + " per measurement. | ";
output += " | ";
output += "
";
$("#consolTableBody").append(output);
$("#newitem_" + window.log_consolidation_table_count + " button.removeButton").bind('click', {item: "#newitem_" + window.log_consolidation_table_count}, function(e)
{
$(e.data.item).remove();
});
window.log_consolidation_table_count++;
});
<&/javascript>